@extends('admin.layout')

@if(session('master') -> prerogative == '1')

  @section('content')

        <!-- Content Wrapper. Contains page content -->
      <div class="content-wrapper">
         
          <div id="breadcrumbs" class="breadcrumbs">
              <ol class="breadcrumb">
              <li><a href="javascript:void();"><i class="fa fa-home"></i>&nbsp;&nbsp;后台首页</a></li>
                      
                      <li><a href="javascript:void();">权限管理</a></li>    
                      <li><a href="javascript:void();">管理员列表</a></li>          
              </ol>
          </div>

              @if(session('info'))
                <div class="row">
                  <div class="col-xs-6 col-xs-offset-3">
                    <div id="showHidden" class="alert alert-success alert-dismissable">
                      <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                      <h4>  <i class="icon fa fa-check"></i> {{ session('info') }} </h4>
                      
                    </div>
                  </div>
                </div>
              @endif

              @if(session('error'))
                <div class="row">
                  <div class="col-xs-6 col-xs-offset-3">
                    <div id="showHidden" class="alert alert-danger alert-dismissable">
                    <button aria-hidden="true" data-dismiss="alert" class="close" type="button">x</button>
                        <h4><i class="icon fa fa-ban"></i>{{ session('error') }} </h4>
                    </div>
                  </div>
                </div>
             @endif


          <section class="content">
         <div class="row">
              <div class="col-xs-12">
                  <div class="box">
                   <div class="box-header">
                      <nav class="navbar navbar-default">      
                          <div class="collapse navbar-collapse">
                            <form method="get" action="{{ asset('admin/admin/index') }}" class="navbar-form form-inline">
                              <div class="form-group">
                                   <input type="text" value="{{ $request['keyword']  or '' }}" name="keyword" class="form-control" placeholder="请输入邮箱地址">
                              </div>
                              <button class="btn btn-default" type="submit">查找</button>
                              <div class="form-group pull-right">
                                  <a class="btn btn-primary pull-right" href="{{ asset('/admin/admin/add') }}"><i class="fa fa-plus"></i>添加管理员</a>
                              </div>                
                            </form>        
                          </div>
                      </nav>  
                   </div>              
                   <div class="box-body">                
                      <div class="row">
                      <div class="col-sm-12">
                        <table class="table table-bordered table-striped dataTable" id="list-table">
                           <thead>
                             <tr align="center" role="row">
                                 <th>ID</th>
                                 <th>用户头像</th>
                                 <th>用户名</th>
                                 <th>昵称</th>
                                 <th>所属角色</th>
                                 <th>状态</th>
                                 <th>Email地址</th>
                                 <th>创建时间</th>
                                 <th>更新时间</th>
                                 <th>最后登录时间</th>
                                 <th>最后登录IP</th>
                                 <th>操作</th>
                             </tr>
                           </thead>
                          <tbody>

                          @foreach($data as $user)
                            <tr align="center" role="row">
                               <td class="ids" value="{{ $user -> id}}">
                                @if($user -> id == 999999)
                                  0
                                @else
                                  {{ $user -> id}}
                                @endif

                               </td>
                               <td><img width="50" height="50" src="{{ $user -> img}}"></td>
                               <td>{{ $user -> username}}</td>
                               <td>{{ $user -> nickname}}</td>
                               <td>
                                
                                @if($user -> prerogative == 0)

                                  普通管理员
                                @elseif($user -> prerogative == 1)

                                  超级管理员

                                @endif
                               </td>
                              <td class="std btn">
                               @if($user -> status == 1)
                                  <span class=" btn btn-success">启用</span> 
                               @else
                                  <span class=" btn btn-danger">禁用</span> 
                               @endif
                               </td>
                              
                               <td>{{ $user -> email}}</td>
                               <td>{{ $user -> created_at}}</td>
                               <td>

                                @if(!empty($user -> updated_at))

                                  {{ $user -> updated_at}}
                                @else
                                    无更新
                                @endif

                               </td>
                               <td>
                                @if(!empty($user -> last_time))
                                   {{ $user -> last_time}}
                                @else
                                    未登录
                                @endif

                               </td>
                               <td>
                                @if(!empty($user -> last_ip))
                                   {{ $user -> last_ip}}
                                @else
                                    未登录
                                @endif

                               </td>
                              
                               <td>
                                  <a href="{{ url('/admin/admin/edit/')}}/{{ $user -> id}} " class="btn btn-primary"><i class="fa fa-pencil"></i></a>
                                  @if($user -> username != 'admin' )
                                    <a href="{{ url('/admin/admin/delete/')}}/{{ $user -> id}}" class="btn btn-danger"><i class="fa fa-trash-o"></i></a>
                                  @endif


                                  
                              </td>
                             </tr>  
                          @endforeach                       
                           </tbody>
                         </table>  
                     </div>
                </div>
               </div>
              </div>
          </div>
         </div>
     </section>

      </div><!-- /.content-wrapper -->

      <script type="text/javascript">
        
        window.onload = function()
        {

              //自动清楚提示框
              setTimeout("$('#showHidden').hide( )",3000); 


              $.ajaxSetup({
              headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
              }
            });

            //添加事件
            
            
              //鼠标移入事件
              $('.std').on('mouseover', function(){

                $(this).css({cursor:'pointer', color:'#fff'});
              })
              //鼠标移出事件
              $('.std').on('mouseout', function(){

                $(this).css({cursor:'default', color:'#fff'});
              })
          
            


            $('.std').on('click', function(){

              var std = $(this);
              var id = $(this).parent().find('.ids').attr('value');
              // var id = $(this ).parent().children().first().html();
              
              if(id == '999999')
              {
                std.html('<span class=" btn btn-block btn-success disabled">启用</span>');
              } 
              
              if(id < '999999')
              {
                // alert(id);
                $.post('/admin/admin/ajaxUpdate',{id:id},function(data){
                  if(data =='0')
                  {
                    std.html('<span class=" btn btn-success">启用</span>');
                  }else if(data == '2')
                  {
                    std.html('<span class=" btn btn-danger">禁用</span>');
                    
                  }
                },'json');
              }

            });

        }
      </script>



  @endsection

@else 
@section('content')
 <div class="content-wrapper">
    <div class="alert alert-danger alert-dismissable">
      <h4><i class="icon fa fa-ban"></i> 非法操作 </h4>
      <h2>！您没有权限访问此页面，请终止当前操作，否则将追究法律责任！</h2>
    </div>
  </div>

@endsection
@endif